package tests;

import junit.framework.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import Model.SetTaskStatusCommand;
import Model.Task;

/**
 * JUnit test case for SetTaskStatusCommandTest
 */

public class SetTaskStatusCommandTest extends TestCase {
	//declare reusable objects to be used across multiple tests
    SetTaskStatusCommand t1;
    ArrayList<Task> arrList=null;
	Date utilDate = new Date();
	Task newtask;
	
	String var1 = "Task 1";
	
	public SetTaskStatusCommandTest(String name) {
		super(name);
	}

	@Before
	protected void setUp() {
	//define reusable objects to be used across multiple tests
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
	    
		try { 

		 utilDate = df.parse("15/11/2011");
		 newtask = new Task("Task 1",utilDate,"Type 1");
	     arrList = new ArrayList<Task>();
	     arrList.add(newtask);
		 

	     
		 t1 = new SetTaskStatusCommand(arrList);
			 
				} 
				
				catch (ParseException e) {
					e.printStackTrace();
				}	
	
	}

	@Test
	public void testSetTaskStatusCommandConstructor() {

		SetTaskStatusCommand var0 = new SetTaskStatusCommand(arrList);
		assertNotNull("Object is created",var0);

	}
	
	@Test
	public void testExecute() {

		assertEquals(arrList.size(),1);
		t1.execute(var1,true);
		assertEquals(arrList.get(0).getDone(),true);
		t1.execute(var1,false);
		assertEquals(arrList.get(0).getDone(),false);
	}
	
	@Test
	public void testUndo() {

		assertEquals(arrList.size(),1);
		t1.execute(var1,true);
		assertEquals(arrList.get(0).getDone(),true);
		t1.execute(var1,false);
		t1.undo();
		assertEquals(arrList.get(0).getDone(),true);
	}
	
	@Test
	public void testRedo() {

		assertEquals(arrList.size(),1);
		t1.execute(var1,true);
		assertEquals(arrList.get(0).getDone(),true);
		t1.undo();
		assertEquals(arrList.get(0).getDone(),false);
		t1.redo();
		assertEquals(arrList.get(0).getDone(),true);

	}
}